package com.zyc.studentstudy.ui.youdao

import android.text.TextUtils
import android.webkit.JavascriptInterface
import com.zyc.studentstudy.utils.GlobalDispatcher
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

/**
 * Created by zhangyuncai on 2018/11/27.
 */
abstract class JsCall : Any() {
    //给html提供的有参函数，html调用我们这个方法 ： window.Android.HtmlcallJava2("IT-homer blog");
    @JavascriptInterface
    fun HtmlcallJava2(param: String) {
        if (!TextUtils.isEmpty(param)) {
            if (param.contains("...")) {
                return
            }
            GlobalDispatcher.launchIO {
                withContext(Dispatchers.Main) {
                    callbackParam(param);
                }
            }
        }
    }

    abstract fun callbackParam(param: String?)
}
